package suncertify.application;

import suncertify.application.exceptions.DatabaseFileNotFoundException;
import suncertify.application.exceptions.DatabaseFileNotReadableException;
import suncertify.application.exceptions.DatabaseFileNotWritableException;
import suncertify.application.exceptions.DatabaseFileWrongTypeException;
import suncertify.application.exceptions.InvalidServerNameException;
import suncertify.contractors.ContractorsAccess;
import suncertify.gui.dialogs.ClientConnectionDialog;

/**
 * This interface represents the controller and view of the {@link ClientConnectionDialog} dialog. This interface
 * represents a simplified version of the Model View Controller pattern, where the controller and view can be
 * implemented by one class. This interface makes the {@link ClientConnectionDialog} independent of a specific class or
 * classes.
 * 
 * @see ClientConnectionDialog
 * @see ClientApplication
 */
public interface ClientConnectionDialogInterface {

    /**
     * Method that returns the database file path to the caller.
     * 
     * @return The database file path.
     */
    public String getDatabaseFilePath();

    /**
     * Method that returns the server name to the caller.
     * 
     * @return Server name.
     */
    public String getServerName();

    /**
     * Method that returns the port number to the caller.
     * 
     * @return The port number.
     */
    public int getPortNumber();

    /**
     * Method definition to create a local {@link ContractorsAccess} implementation from the database file path.
     * 
     * @param filePath
     *            Path to the application's database file.
     * @return Implementors must return true if the file path represents a valid database file and the
     *         {@link ContractorsAccess} instantiation succeeded.
     */
    public boolean createContractorsAccess(String filePath);

    /**
     * Method definition to validate a server name. Implementors of this method must return true if the serverName
     * represents a valid computer name. Implementors of this method must throw <code>InvalidServerNameException</code>
     * if the server name is invalid.
     * 
     * @param serverName
     *            Name of the remote server.
     * @return True if the <code>serverName</code> is valid.
     * @throws InvalidServerNameException
     *             if the <code>serverName</code> is invalid.
     */
    public boolean isServerNameValid(String serverName) throws InvalidServerNameException;

    /**
     * Definition for a method that validates the TCP port number.
     * 
     * @param portNumber
     *            The port number to be validated.
     * @return True if the port number is valid, false otherwise.
     */
    public boolean isPortNumberValid(int portNumber);

    /**
     * Method definition for implementors who want to create an instance of the <code>RemoteContractorsAccessImpl</code>
     * from the <code>serverName</code> and <code>port</code> parameters.
     * 
     * @param serverName
     *            Name of the remote server.
     * @param port
     *            Port number of the remote server.
     * @return Implementors should return true only if the instantiation of the <code>RemoteContractorsAccessImpl</code>
     *         class succeeds.
     */
    public boolean createRemoteContractorsAccess(String serverName, int port);

    /**
     * A definition for a method that validates the application's database file.
     * 
     * @param databaseFilePath
     *            Path to the database file.
     * @return True if the database file is found in the file system, has the correct extension, is readable and
     *         writable, otherwise false.
     * @throws DatabaseFileNotFoundException
     *             Thrown if the file is not found.
     * @throws DatabaseFileWrongTypeException
     *             Thrown if the file has the wrong extension.
     * @throws DatabaseFileNotReadableException
     *             Thrown if the file is not readable.
     * @throws DatabaseFileNotWritableException
     *             Thrown if the file is not writable.
     */
    public boolean isDatabaseFileValid(String databaseFilePath) throws DatabaseFileNotFoundException,
	    DatabaseFileWrongTypeException, DatabaseFileNotReadableException, DatabaseFileNotWritableException;

    /**
     * Definition for a method that returns the user's current working directory.
     * 
     * @return User's current working directory.
     */
    public String getUserCurrentDirectory();
}
